#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import PropertiesReader
import GenCustomRules
import xml.etree.ElementTree as etree
import xml.dom.minidom

class ClassPathFileReader(object):
	#输入一个目录名，返回该工程依赖的第三方jar包的list
	def getOneProThirdJarList(self,projectname,filename):
		projectname = projectname.replace("\\","/")
		tree = etree.parse(projectname+"/"+filename)
		root = tree.getroot()

		thirdjarlist = []
		for elem in root.findall('classpathentry'):
			kind = elem.get("kind")
			if(kind == "lib"):
				lib = elem.get("path")
				thirdjarlist.append(lib)

		return thirdjarlist
	
	#输入一个目录名，返回该工程的工程名
	def getProjectName(self,project,filename):
		project = project.replace("\\","/")
		dom = xml.dom.minidom.parse(project+"/"+filename)
		root = dom.documentElement
		bb = root.getElementsByTagName('name')
		b = bb[0]

		return b.firstChild.data

if __name__=="__main__":
	filereader = ClassPathFileReader()
	print( filereader.getOneProThirdJarList("E:/SVN/CasualGames/plugin/plugins/umeng/proj.android",".classpath") )
	print( filereader.getProjectName("E:/SVN/CasualGames/popfarm_v6_four/proj.android",".project") )
